import 'package:base/main.dart';
import 'package:flutter/material.dart';
import 'package:module_discover/enums/domain_type_enum.dart';
import 'package:module_discover/pages/filter_domain/widgets/child/child_checkbox_widget.dart';
import 'package:module_discover/pages/filter_domain/widgets/child/child_input_widget.dart';
import 'package:module_discover/pages/filter_domain/widgets/child/child_single_widget.dart';
import 'package:module_discover/pages/model/filter_model.dart';

import '../child/child_select_widget.dart';

class ContentItemWidget extends StatelessWidget {
  String parentKey;
  BaseFilterItem? child;

  ContentItemWidget({super.key, required this.parentKey, required this.child});

  @override
  Widget build(BuildContext context) {
    return SingleChildScrollView(
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        mainAxisAlignment: MainAxisAlignment.start,
        children: [
          Text(
            '${child?.title}',
            style: TextStyle(
              fontSize: 13,
              color: Colors.black,
              fontWeight: FontWeight.bold,
            ),
          ),
          _buildChildWidget(child!),
          SizedBox(height: 16),
        ],
      ),
    );
  }

  _buildChildWidget(BaseFilterItem child) {
    final type = DomainTypeEnum.fromValue(child.type);
    switch (type) {
      case DomainTypeEnum.INPUT:
        return ChildInputWidget(
          child: child,
          parentKey: parentKey,
        );
      case DomainTypeEnum.CHECKBOX:
        return ChildBxoWidget();
      case DomainTypeEnum.S_CHOICE:
        return ChildSingleWidget(
          child: child,
        );
      case DomainTypeEnum.M_CHOICE:
        return ChildSingleWidget(
          child: child,
        );
      case DomainTypeEnum.SELECT2:
        return ChildSelectWidget(
          parentKey: parentKey,
          child: child,
        );
      default:
        Log.d('CONTENT 未知类型');
        return SizedBox();
    }
  }
}
